function Stream(name, data, color, hidden, mode, view)
{
	/**
	 * We need to be drawn
	 */
	this.update = function ()
	{
		// Tell our view that it is dirty
		View.views[this.view].update();
	}
	
	/**
	 * Stream attributes
	 */
	this.name = name;
	this.setName = function (name)
	{
		// TODO : Check if other streams have the same name
		this.name = name;
		
		this.update();
	}
	
	this.data = data || [];
	this.setData = function (data)
	{
		this.data = data;
		
		this.update();
	}
	this.setDataFromRaw = function (rawData)
	{
		var data = [];
		
		jQuery.each(
			rawData, function ()
			{
				data.push(
					[this[1] * 1000, this[3], this[2] * 1000]);
			});
		
		this.setData(data);
	}
	
	this.color = color || Color.newById(Math.abs(crc32(name)) % 100);
	this.setColor = function (color)
	{
		// TODO: Check if this is a valid color
		// TODO: Check if another stream has the same color ?
		this.color = color;
		
		this.update();
	}
	this.getColor = function ()
	{
		return this.color.toString();
	}
	
	this.hidden = hidden || false;
	this.setHidden = function (hidden)
	{
		this.hidden = hidden;
		
		this.update();
	}
	
	this.view = view || View.MIN;
	this.setView = function (view)
	{
		// Tell old view that it is dirty
		this.update();
		
		this.view = clamp(view, View.MIN, View.MAX);
		
		this.update();
	}
	
	this.setMode = function (mode)
	{
		this.bars  = false;
		this.lines = false;
		
		switch (mode) {
			case 'lines': this.lines = true; break;
			case 'bars':
			default: this.bars  = true; break;
		}
		
		this.update();
	}
	this.lines = mode === 'lines' ? true : false;
	this.bars  = mode === 'lines' ? false : true;
	this.getMode = function ()
	{
		if (this.bars) {
			return 'bars';
		} else if (this.lines) {
			return 'lines';
		} else {
			return null;
		}
	}
	this.switchMode = function ()
	{
		if (this.bars) {
			this.setMode('lines');
		} else {
			this.setMode('bars');
		}
	}
	
	/**
	 * We are being drawn
	 */
	this.plot = function ()
	{
		if (this.hidden) {
			// We aren't visible
			return {};
		}
		
		// Return Flot data object for this data series
		return {
			color: this.getColor(),
			label: this.name,
			bars:  this.bars,
			lines: this.lines,
			data:  this.data}
	}
}

Stream.streams = {};

/**
 * Create streams
 */
Stream.push = function (name)
{
	Stream.streams[name] = new Stream(name);
}

Stream.remove = function (name)
{
	View.view[Stream.streams[name].view].update();
	
	delete Stream.streams[name];
}

Stream.select = function (id)
{
	var selectHTML = '<select id="' + id + '">';
	
	jQuery.each(
		Stream.streams, function (name)
		{
			selectHTML += '<option value="' + name + '">' + name + '</option>';
		});
	
	selectHTML += '</select>';
	
	return selectHTML;
}
